﻿namespace CKFinder.Connector.CommandHandlers
{
    using CKFinder.Connector;
    using System;
    using System.Text.RegularExpressions;
    using System.Web;

    internal class QuickUploadCommandHandler : FileUploadCommandHandler
    {
        protected override string GetJavaScriptCode(int errorNumber, string fileName, string fileUrl)
        {
            HttpRequest request = HttpContext.Current.Request;
            string str = request.QueryString["CKEditor"];
            string input = request.QueryString["CKEditorFuncNum"];
            string str3 = "";
            if ((str == null) || (input == null))
            {
                int num = errorNumber;
                if (((num != 0) && (num != 0xc9)) && (num != 0xcf))
                {
                    return ("window.parent.OnUploadCompleted(" + errorNumber + ") ;");
                }
                return string.Concat(new object[] { "window.parent.OnUploadCompleted(", errorNumber, ",'", fileUrl.Replace("'", @"\'"), "','", fileName.Replace("'", @"\'"), "') ;" });
            }
            input = Regex.Replace(input, "[^0-9]", "", RegexOptions.None);
            if (errorNumber > 0)
            {
                str3 = Lang.getErrorMessage(errorNumber).Replace("%1", fileName);
                if (errorNumber != 0xc9)
                {
                    fileUrl = "";
                }
            }
            return ("window.parent.CKEDITOR.tools.callFunction(" + input + ",'" + fileUrl.Replace("'", @"\'") + "','" + str3.Replace("'", @"\'") + "') ;");
        }
    }
}

